package com.gitee.empty_null.spark;

import cn.hutool.json.JSONUtil;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xuhainan
 * @date 2023/9/5 09:26
 * @region hefei
 */
@Data
public class SparkChatResponse {

    public static Response parse(String message) {
        return JSONUtil.toBean(message, Response.class);
    }

    public static String content(String message) {
        return parse(message).getPayload().getChoices().getText().stream().map(Text::getContent).collect(Collectors.joining());
    }

    @Data
    public static class Response {
        Header header;
        Payload payload;
    }

    @Data
    public static class Header {
        int code;
        int status;
        String sid;
    }

    @Data
    public static class Payload {
        Choices choices;
    }

    @Data
    public static class Choices {
        List<Text> text;
    }

    @Data
    public static class Text {
        String role;
        String content;
    }
}
